package approve.action;

import project.active.LogoutActivity;
import model.pojo.Employee;
import models.util.UtilInitLang;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class MainEApproval extends Activity{
	TextView logout,username,home,welcome;
	String lang = "EN",database;
	Bundle language;
	Employee emp= new Employee();
	UtilInitLang utilang=new UtilInitLang();

	ListView lstApprove;

	public UtilInitLang getUtilang() {
		return utilang;
	}

	public void setUtilang(UtilInitLang utilang) {
		this.utilang = utilang;
	}


	public String getDatabase() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			database = extras.getString("database");
		}
		return database;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.maineapproval);
		lstApprove = (ListView)findViewById(R.id.listApproval);

		language = getIntent().getExtras().getBundle(getLang());

		Intent currentIntent = this.getIntent();
		emp=(Employee) getIntent().getExtras().get("em");
		emp = (Employee)currentIntent.getSerializableExtra("em");

		//		    showDialogMessage();
		logout=(TextView)findViewById(R.id.logout);
		username=(TextView)findViewById(R.id.username);
		logout.setText(language.getString("Logout"));

		logout.setOnClickListener(listenerLogout);
		username.setText(emp.getUserName());
		
		welcome = (TextView)findViewById(R.id.welcome);
		welcome.setText(language.getString("ac_Welcome"));
		
		home = (TextView)findViewById(R.id.home);
		home.setText(language.getString("ac_home"));
		
		 home.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					Intent intent = new Intent(MainEApproval.this,MainList.class);
					
					intent.putExtra("lang", getLang());
					intent.putExtra("database", getDatabase());
					intent.putExtra("em",emp);
					intent.putExtras(getIntent().getExtras());
					startActivity(intent);
				}
			});

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainEApproval.this,android.R.layout.simple_list_item_1,listAllApprove(getLang()));
		lstApprove.setAdapter(adapter); 
		lstApprove.setOnCreateContextMenuListener(MainEApproval.this);
		OnItemClickListener listener = new OnItemClickListener() {


			public void onItemClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				String item = arg0.getItemAtPosition(arg2).toString();
				if(item.equals("New Document") || item.equals("기안하기") ||item.equals("TÃ¡ÂºÂ¡o VÃ„Æ’n BÃ¡ÂºÂ£n")){
					Intent intent = new Intent(MainEApproval.this,ApporoveNewActivity.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtra("em", emp);
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}else if(item.equals("Pending Document")|| item.equals("ÃªÂ²Â°Ã¬Å¾Â¬Ã«Å’â‚¬ÃªÂ¸Â°Ã«Â¬Â¸Ã¬â€žÅ“") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n chÃ¡Â»ï¿½ duyÃ¡Â»â€¡t")){
					Intent intent = new Intent(MainEApproval.this,Re_PendingDocument.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}else if(item.equals("Not approved document")|| item.equals("Ã«Â¯Â¸ÃªÂ²Â°Ã¬Å¾Â¬Ã«Â¬Â¸Ã¬â€žÅ“ ") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n chÃ†Â°a duyÃ¡Â»â€¡t")){
					Intent intent = new Intent(MainEApproval.this,Re_NotApprovedDocument.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);

				}else if(item.equals("Approved document")|| item.equals("ÃªÂ²Â°Ã¬Å¾Â¬Ã¬â„¢â€žÃ«Â£Å’Ã«Â¬Â¸Ã¬â€žÅ“") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n Ã„â€˜ÃƒÂ£ duyÃ¡Â»â€¡t")){
					Intent intent = new Intent(MainEApproval.this,Re_ApprovedDocument.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}else if(item.equals("Decline document")|| item.equals("Ã«Â°ËœÃ«Â Â¤Ã«Â¬Â¸Ã¬â€žÅ“") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n bÃ¡Â»â€¹ tÃ¡Â»Â« chÃ¡Â»â€˜i")){
					Intent intent = new Intent(MainEApproval.this,Re_DeclineDocument.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}else if(item.equals("Meeting document pending")|| item.equals("Ã«â€šÂ´ÃªÂ°â‚¬ Ã«Â°â€ºÃ¬ï¿½â‚¬ Ã­Å¡Å’Ã¬ï¿½ËœÃ«Â¡ï¿½") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n cuÃ¡Â»â„¢c hÃ¡Â»ï¿½p nhÃ¡ÂºÂ­n")){
					Intent intent = new Intent(MainEApproval.this,Re_MeetingDocumentPendding.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
					//					}else if(item.equals("Meeting document sending")|| item.equals("Ã«â€šÂ´ÃªÂ°â‚¬ Ã¬ËœÂ¬Ã«Â¦Â° Ã­Å¡Å’Ã¬ï¿½ËœÃ«Â¡ï¿½") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n cuÃ¡Â»â„¢c hÃ¡Â»ï¿½p gÃ¡Â»Â­i")){
					//						
				}else if(item.equals("Reference document")|| item.equals("Ã¬Â°Â¸Ã¬Â¡Â°Ã«Â¬Â¸Ã¬â€žÅ“Ã­â€¢Â¨") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n tham khÃ¡ÂºÂ£o")){
					Intent intent = new Intent(MainEApproval.this,Re_ReferenceDocument.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);

					/*Start MaiMai*/
				}else if(item.equals("My Document sending")|| item.equals("내가 올린 문서") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n Ã„â€˜ÃƒÂ£ gÃ¡Â»Å¸i")){
					Intent intent = new Intent(MainEApproval.this,My_App_DocumentSending.class);
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);

				}else if(item.equals("My Saved document")|| item.equals("Ã¬Å¾â€žÃ¬â€¹Å“Ã«Â³Â´ÃªÂ´â‚¬") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n lÃ†Â°u")){
					Intent intent = new Intent(MainEApproval.this,My_App_SavedDocument.class);
					//System.out.println(lang +"--------- "+ getDatabase());
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}
				else if(item.equals("My Approved document")|| item.equals("ÃªÂ²Â°Ã¬Å¾Â¬Ã¬â„¢â€žÃ«Â£Å’Ã«Â¬Â¸Ã¬â€žÅ“") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n duyÃ¡Â»â€¡t")){
					Intent intent = new Intent(MainEApproval.this,My_App_ApprovedDocument.class);
					//System.out.println(lang +"--------- "+ getDatabase());
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}
				else if(item.equals("My Decline document")|| item.equals("Ã«Â°ËœÃ«Â Â¤Ã«Â¬Â¸Ã¬â€žÅ“") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n tÃ¡Â»Â« chÃ¡Â»â€˜i")){
					Intent intent = new Intent(MainEApproval.this,My_App_DeclineDocument.class);
					//System.out.println(lang +"--------- "+ getDatabase());
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}
				else if(item.equals("My Meeting document sending")|| item.equals("Ã«â€šÂ´ÃªÂ°â‚¬ Ã¬ËœÂ¬Ã«Â¦Â° Ã­Å¡Å’Ã¬ï¿½ËœÃ«Â¡ï¿½i") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n hÃ¡Â»ï¿½p gÃ¡Â»Â­i")){
					Intent intent = new Intent(MainEApproval.this,My_App_MeetingDocumentSendding.class);
					//System.out.println(lang +"--------- "+ getDatabase());
					intent.putExtra("lang", lang);
					intent.putExtra("database", getDatabase());
					intent.putExtras(getIntent().getExtras());
					startActivityForResult(intent, 0);
				}
				else if(item.equals("Personal")|| item.equals("ÃªÂ°Å“Ã¬ï¿½Â¸ÃªÂ²Â°Ã¬Å¾Â¬Ã«ï¿½Â¼Ã¬ï¿½Â¸") ||item.equals("CÃƒÂ¡ nhÃƒÂ¢n")){

				}
				/*End MaiMai*/
				else if(item.equals("Department")|| item.equals("Ã«Â¶â‚¬Ã¬â€žÅ“") ||item.equals("PhÃƒÂ²ng Ban")){



				}else if(item.equals("Saved document")|| item.equals("Ã¬Å¾â€žÃ¬â€¹Å“Ã«Â³Â´ÃªÂ´â‚¬") ||item.equals("VÃ„Æ’n bÃ¡ÂºÂ£n Ã„â€˜Ã†Â°Ã¡Â»Â£c lÃ†Â°u")){


				}
			}

		};
		lstApprove.setOnItemClickListener(listener);
	}

	public String getLang() {
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			lang = extras.getString("lang");
		}
		return lang;
	}

	private OnClickListener listenerLogout=new OnClickListener() {

		public void onClick(View v) {
			LoginActivity.flagupdateversion=false;

			Intent i=new Intent(MainEApproval.this, LogoutActivity.class);
			i.putExtra("database", getDatabase());
			startActivity(i);
		}
	};

	public String[] listAllApprove(String value) {
		String[] menu = null;
		if (value.equals("EN")) {
			menu = getResources().getStringArray(R.array.approval_en);
		} else if (value.equals("KR")) {
			menu = getResources().getStringArray(R.array.approval_kr);
		} else {
			menu = getResources().getStringArray(R.array.approval_vn);
		}
		return menu;
	}
}
